@extends('admin.common.main')

@section('cnt')
    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span> 节点中心
        <span class="c-gray en">&gt;</span> 节点修改
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
           href="javascript:location.replace(location.href);" title="刷新">
            <i class="Hui-iconfont">&#xe68f;</i>
        </a>
    </nav>

    <article class="page-container">

        <form id="form-member-add" action="{{ route('admin.node.update',['id' => $node['id']]) }}" class="form form-horizontal">
            @csrf
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">父级：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span class="select-box" style="width:150px;">
                        <select class="select" value="15" name="pid" size="1">
                            <option value="0">顶级</option>
                            @foreach($data as $item)
                                <option @if($item['id'] == $node['pid']) selected
                                        @endif value="{{ $item['id'] }}">
                                    {{ $item['html'] }}{{ $item['name'] }}
                                </option>
                            @endforeach
                        </select>
                    </span>
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">
                    <span class="c-red">*</span>节点名称：
                </label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" name="name" value="{{ $node['name'] }}">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">路由别名：
                </label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" name="route_name" value="{{ $node['route_name'] }}">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">
                    <span class="c-red">*</span>是否主菜单：
                </label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                    <div class="radio-box">
                        <input type="radio" name="is_menu" value="0" @if($node['is_menu'] == 0) checked @endif>
                        <label for="sex-1">否</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" name="is_menu" value="1" @if($node['is_menu'] == 1) checked @endif>
                        <label for="sex-2">是</label>
                    </div>
                </div>
            </div>

            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="确认修改">
                </div>
            </div>
        </form>
    </article>
@endsection

@section('js')
    {{--// 引入验证的jquery--}}
    <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
    <script type="text/javascript" src="/admin/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="/admin/lib/laypage/1.2/laypage.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
    <script>
        $("#form-member-add").validate({
            rules: {
                name: {
                    required: true
                },
                pid: {
                    required: true
                },
                is_menu: {
                    // 密码一致 需是ID
                    required: true
                },
            },
            onkeyup: false,
            success: "valid",
            submitHandler: function (form) {
                // 验证成功 提交表单
                let url = $(form).attr('action');
                let data = $(form).serialize();
                $.ajax({
                    url,
                    data,
                    type: "PUT",
                }).then(({msg, status}) => {
                    if (status == 200) {
                        layer.msg(msg, {icon: 1, time: 900});
                        location.href = '{{ route('admin.node.index') }}';
                    } else {
                        layer.msg(msg, {icon: 2, time: 900});
                    }
                })
            },
        })
    </script>
@endsection
